package com.zj.fx.service.month;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zj.fx.common.base.BaseService;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.mapper.month.MonthNecessaryMapper;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.model.info.InfoNecessary;
import com.zj.fx.model.info.InfoNecessaryExample;
import com.zj.fx.model.info.InfoSupply;
import com.zj.fx.model.month.MonthConstant;
import com.zj.fx.model.month.MonthNecessary;
import com.zj.fx.model.month.MonthNecessaryExample;
import com.zj.fx.model.month.MonthSupplytask;
import com.zj.fx.shiro.util.ShiroUtils;
import com.zj.fx.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 必备条件指标库表 MonthNecessaryService
 * @Title: MonthNecessaryService.java 
 * @Package com.zj.fx.service 
 * @author SQL_自动生成
 * @email ${email}
 * @date 2023-06-13 15:02:42  
 **/
@Service
public class MonthNecessaryService implements BaseService<MonthNecessary, MonthNecessaryExample> {
    @Autowired
    private MonthNecessaryMapper monthNecessaryMapper;

                                                                                                                                                                                                                
    /**
     * 分页查询
     * @param
     * @param
     * @return
     */
    public PageInfo<MonthNecessary> list(Tablepar tablepar,MonthNecessary monthNecessary) {
            MonthNecessaryExample testExample = new MonthNecessaryExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(monthNecessary);
        }
        //表格排序
        //if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        //}else{
        //	testExample.setOrderByClause("id ASC");
        //}
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<MonthNecessary> list = monthNecessaryMapper.selectByExample(testExample);
        PageInfo<MonthNecessary> pageInfo = new PageInfo<MonthNecessary>(list);
        return pageInfo;
    }
    
        @Override
        public int deleteByPrimaryKey(String ids) {
            
                List<String> lista = ConvertUtil.toListStrArray(ids);
                    MonthNecessaryExample example = new MonthNecessaryExample();
                example.createCriteria().andIdIn(lista);
                return monthNecessaryMapper.deleteByExample(example);

            
        }


        @Override
        public MonthNecessary selectByPrimaryKey(String id) {
            
                return monthNecessaryMapper.selectByPrimaryKey(id);
            
        }


        @Override
        public int updateByPrimaryKeySelective(MonthNecessary record) {
            return monthNecessaryMapper.updateByPrimaryKeySelective(record);
        }

    
    /**
     * 添加
     */
    @Override
    public int insertSelective(MonthNecessary record) {
        
            //添加雪花主键id
            record.setId(SnowflakeIdWorker.getUUID());

        
        return monthNecessaryMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(MonthNecessary record, MonthNecessaryExample example) {

        return monthNecessaryMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(MonthNecessary record, MonthNecessaryExample example) {

        return monthNecessaryMapper.updateByExample(record, example);
    }

    @Override
    public List<MonthNecessary> selectByExample(MonthNecessaryExample example) {

        return monthNecessaryMapper.selectByExample(example);
    }


    @Override
    public long countByExample(MonthNecessaryExample example) {

        return monthNecessaryMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(MonthNecessaryExample example) {

        return monthNecessaryMapper.deleteByExample(example);
    }

    public List<MonthNecessary> selectAll() {
        MonthNecessaryExample monthNecessaryExample = new MonthNecessaryExample();
        MonthNecessaryExample.Criteria criteria = monthNecessaryExample.createCriteria();
        criteria.andIdIsNotNull();
        return monthNecessaryMapper.selectByExample(monthNecessaryExample);
    }

    public PageInfo<MonthNecessary> list2(Tablepar tablepar,MonthNecessary monthNecessary) {
        String supplyId = ShiroUtils.getSupplyId();
        monthNecessary.setFkSupplyId(supplyId);
        //分页查询
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<MonthNecessary> list = monthNecessaryMapper.query4self(monthNecessary);
        PageInfo<MonthNecessary> pageInfo = new PageInfo<MonthNecessary>(list);
        return pageInfo;
    }
    /*
        生成月度评价任务时生成月度必备项目数据
     */
    public Integer generateNes(InfoSupply infoSupply, MonthSupplytask monthSupplytask, InfoNecessary infoNecessary) {
        MonthNecessary monthNecessary = new MonthNecessary();
        monthNecessary.setId(SnowflakeIdWorker.getUUID());
        monthNecessary.setNum(infoNecessary.getNum());
        monthNecessary.setFirstProject(infoNecessary.getFirstProject());
        monthNecessary.setSecondProject(infoNecessary.getSecondProject());
        monthNecessary.setTestMode(infoNecessary.getTestMode());
        monthNecessary.setEvaluationPeriod(infoNecessary.getEvaluationPeriod());//0627 改为枚举
        monthNecessary.setResDeptId(infoNecessary.getResDeptId());
        monthNecessary.setResDeptName(infoNecessary.getResDeptName());
        monthNecessary.setSupportingFileMemo(infoNecessary.getSupportingFileMemo());
        monthNecessary.setFkSupplyId(infoSupply.getId());
        monthNecessary.setSupplyName(infoSupply.getName());
        monthNecessary.setFkTaskId(monthSupplytask.getId());
        monthNecessary.setTaskState(MonthConstant.DTL_STATE_NOFILL);
        return monthNecessaryMapper.insertSelective(monthNecessary);
    }

    public List<MonthNecessary> getTabExist(String id) {
        MonthNecessaryExample monthNecessaryExample = new MonthNecessaryExample();
        MonthNecessaryExample.Criteria criteria = monthNecessaryExample.createCriteria();
        criteria.andFkTaskIdEqualTo(id);
        criteria.andResDeptIdEqualTo(ShiroUtils.getDepId());
        return monthNecessaryMapper.selectByExample(monthNecessaryExample);
    }

    public PageInfo<MonthNecessary> listbyDep(Tablepar tablepar,MonthNecessary monthNecessary) {
        //分页查询
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        monthNecessary.setResDeptId(ShiroUtils.getDepId());
        List<MonthNecessary> list = monthNecessaryMapper.query4self(monthNecessary);
        PageInfo<MonthNecessary> pageInfo = new PageInfo<MonthNecessary>(list);
        return pageInfo;
    }

    /**
     * 查询当前部门对应的必备条件中未填写的记录集合
     * @param monthSupplytask
     * @return
     */
    public List<MonthNecessary> findNoAudit(MonthSupplytask monthSupplytask) {
        MonthNecessaryExample monthNecessaryExample = new MonthNecessaryExample();
        MonthNecessaryExample.Criteria criteria = monthNecessaryExample.createCriteria();
        criteria.andFkTaskIdEqualTo(monthSupplytask.getId());
        criteria.andResDeptIdEqualTo(ShiroUtils.getDepId());
        criteria.andTypeReviewIsNull();
        return monthNecessaryMapper.selectByExample(monthNecessaryExample);
    }

    public PageInfo<MonthNecessary> list4selfResult(Tablepar tablepar, MonthNecessary monthNecessary) {
        MonthNecessaryExample monthNecessaryExample = new MonthNecessaryExample();
        monthNecessaryExample.createCriteria().andFkTaskIdEqualTo(monthNecessary.getFkTaskId());
        monthNecessaryExample.setOrderByClause("id ASC");
        //分页查询
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<MonthNecessary> list = monthNecessaryMapper.selectByExample(monthNecessaryExample);
        PageInfo<MonthNecessary> pageInfo = new PageInfo<MonthNecessary>(list);
        return pageInfo;
    }
}
